//
//  SettingViewController.m
//  ForYourBeauty
//
//  Created by Kelly xu on 2019/6/2.
//  Copyright © 2019 changrenTech. All rights reserved.
//

#import "SettingViewController.h"
#import "TitleContentAccessCell.h"
#import "SingleBtnCell.h"
#import "LoginViewController.h"
#import "AccountInfoViewController.h"
#import "EditPwdViewController.h"
#import "FeedBackViewController.h"
#import "NoticeListViewController.h"
@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>{
    
}
@property(nonatomic,weak)IBOutlet UITableView *mainTableView;
@property(nonatomic,strong)NSMutableArray *titleArray;
@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"设置";
    [self configTableView];
}
-(void)configTableView{
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.tableFooterView = [UIView new];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"TitleContentAccessCell" bundle:nil] forCellReuseIdentifier:@"TitleContentAccessCell"];
    [self.mainTableView registerNib:[UINib nibWithNibName:@"SingleBtnCell" bundle:nil] forCellReuseIdentifier:@"SingleBtnCell"];
    self.mainTableView.showsVerticalScrollIndicator = NO;
    self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.mainTableView.backgroundColor = [UIColor clearColor];
}
#pragma mark - UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0) {
        return [self.titleArray count];
    }else{
        return 1;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1) {
        return 64;
    }
    return 44;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        TitleContentAccessCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TitleContentAccessCell" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor clearColor];
        cell.contentView.backgroundColor = [UIColor clearColor];
        if (indexPath.row==0) {
            [cell.bgImageView setImage:[[UIImage imageNamed:@"topBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"topBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"topBg"].size.height/2]];
        }else if (indexPath.row<[self.titleArray count]-1){
            [cell.bgImageView setImage:[[UIImage imageNamed:@"middleBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"middleBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"middleBg"].size.height/2]];
        }else{
            [cell.bgImageView setImage:[[UIImage imageNamed:@"bottomBg"] stretchableImageWithLeftCapWidth:[UIImage imageNamed:@"bottomBg"].size.width/2 topCapHeight:[UIImage imageNamed:@"bottomBg"].size.height/2]];
        }
        cell.titleLab.text = [self.titleArray objectAtIndex:indexPath.row];
        return cell;
    }else{
        SingleBtnCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SingleBtnCell" forIndexPath:indexPath];
        [cell.sureBtn setTitle:@"退出登录" forState:UIControlStateNormal];
        [cell.sureBtn addTarget:self action:@selector(logOut) forControlEvents:UIControlEventTouchUpInside];
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        switch (indexPath.row) {
            case 0:
            {
                AccountInfoViewController *accountInfo = [[AccountInfoViewController alloc]init];
                [self.rt_navigationController pushViewController:accountInfo animated:YES complete:nil];
            }
                break;
            case 1:
            {
                EditPwdViewController *edit = [[EditPwdViewController alloc]init];
                [self.rt_navigationController pushViewController:edit animated:YES complete:nil];
            }
                break;
            case 2:
            {
                NoticeListViewController *noticeList = [[NoticeListViewController alloc]init];
                [self.rt_navigationController pushViewController:noticeList animated:YES complete:nil];
            }
                break;
            case 3:
            {
                FeedBackViewController *feedback = [[FeedBackViewController alloc]init];
                [self.rt_navigationController pushViewController:feedback animated:YES complete:nil];
            }
                break;
            default:
                break;
        }
    }
    
}
#pragma mark - instance
-(NSMutableArray*)titleArray{
    if (!_titleArray) {
        _titleArray = [[NSMutableArray alloc]init];
        [_titleArray addObjectsFromArray:@[@"账号信息",@"修改密码",@"闹钟提醒",@"意见反馈"]];
    }
    return _titleArray;
}
-(void)logOut{
    [[LoginTools sharedTools]removeUserInfo];
    LoginViewController *login = [[LoginViewController alloc]init];
    RTRootNavigationController *nav = [[RTRootNavigationController alloc]initWithRootViewControllerNoWrapping:login];
    [JumpTools setRootCtrl:nav];

}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
